/// <reference path="../_References.ts"/>

class Fps
{
    public enabled = true;
    public value = 'Computing FPS value...';
    public currentMs = 0;
    public previousMs = Date.now();
    public frameCount = 0;

    public draw = function()
    {
        if (!this.enabled) return;
        Game.context.font = "40pt Calibri";
        Game.context.fillStyle = '#000000';
        Game.context.strokeStyle = "blue";
        Game.context.fillText(this.value, 50, 50);

        this.frameCount++;
        this.currentMs = Date.now();

        if (this.currentMs - this.previousMs > 1000)
        {
            this.value = this.frameCount * (this.currentMs - this.previousMs) / 1000;
            this.previousMs += 1000;
            this.frameCount = 0;
        }
    };
}